home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / P_ROBO31.ZIP / HOTSHOT2.PR < prev    next >
Text File  |  1993-02-21  |  6KB  |  169 lines

  1.   PROCEDURE HotShot2;
  2.   {
  3.    Author: David Malmberg
  4.  
  5.    Strategy:  Stay in one place.  Find a foe.  Take a shot.
  6.    Keep improving aim and shooting until foe is lost from sights.
  7.    Then move sights (scanning) to adjacent target area.
  8.    If the Robot scans a complete circle (360 degrees) without
  9.    finding a foe in shooting range, move to another spot on the
  10.    field.  (This will avoid "stand-offs" where opponents stay
  11.    just out of range of one another.)  RaiseShield when standing
  12.    still and lower them when moving.
  13.  
  14.    When damage gets to 70 (or more) or fuel (if using fuel) gets
  15.    below 200 adopt an "End-Game" strategy of moving to the lower
  16.    left corner, lower shield, and continue to scan and shoot in
  17.    the corner's 90 degree range.
  18.  
  19.    This Robot should be VERY effective against foes which
  20.    are stopped or are moving slowly.  It will be less effective
  21.    against Robots traveling at high speeds.
  22.  
  23.    This Robot has been designed to utilize Fuel (if it is available)
  24.    to power its Shield.  However, it has not been designed to deal
  25.    effectively with Obstructions.
  26.   }
  27.  
  28.  
  29.   VAR { HotShot2 "Global" variables }
  30.  
  31.     Angle, { Scanning angle }
  32.     Last_Damage, { Robot's Last damage value }
  33.     Range, { Range/Distance to foe }
  34.     Sweep, { "Sweep count" -- when = 18, Robot has scanned 360 degrees }
  35.     Delta          : Integer; { Scanning arc }
  36.  
  37.  
  38.     PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
  39. {
  40.  Improve aim by doing a binary search of the target area.
  41.  I.E., divide the target area in two equal pieces and redefine
  42.  the target area to be the piece where the foe is found.
  43.  If the foe is not found, expand the search area to the
  44.  maximum arc of plus or minus 10 degrees.
  45. }
  46.     BEGIN
  47.       Arc := Arc DIV 2; { Divide search area in two. }
  48.       IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
  49.         THEN Ang := Ang-Arc { If foe found, redefine target angle. }
  50.         ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
  51.           THEN Ang := Ang+Arc { If foe found, redefine target angle. }
  52.           ELSE Arc := 10;
  53.       { Foe not found in either piece, expand search area to maximum arc. }
  54.     END; {Aim}
  55.  
  56.  
  57.     PROCEDURE BlastThem;
  58.     BEGIN
  59.       Angle := 10;
  60.       REPEAT
  61.         Delta := 10; { Start with widest scanning arc. }
  62.         Range := scan(Angle, Delta);
  63.         WHILE (Range > 40) AND (ObjectScanned = Enemy)
  64.           AND (Range < MaxMissileRange) DO
  65.         { Must be far enough away to avoid self-damage. }
  66.           BEGIN
  67.             Aim(Angle, Delta); { Improve aim. }
  68.             Cannon(Angle, Range); { Fire!! }
  69.             Range := scan(Angle, Delta); { Is foe still in sights? }
  70.           END;
  71.         Angle := Angle+20; { Look in adjacent target area. }
  72.       UNTIL Angle > 360;
  73.     END;
  74.  
  75.  
  76.     PROCEDURE GOTO(x, y : Integer);
  77.       { Go to location X,Y on playing field. }
  78.     VAR Heading    : Integer;
  79.     BEGIN
  80.       { Find the heading we need to get to the desired spot. }
  81.       Heading := Angle_To(x, y);
  82.  
  83.       { Keep traveling at top speed until we are within 150 meters }
  84.       WHILE (distance(loc_x, loc_y, x, y) > 150) DO
  85.         BEGIN
  86.           Drive(Heading, MaxSpeed);
  87.           BlastThem;
  88.         END;
  89.  
  90.       { Cut speed, and creep the rest of the way. }
  91.       WHILE (distance(loc_x, loc_y, x, y) > 20) DO
  92.         BEGIN
  93.           Drive(Heading, 20);
  94.           BlastThem;
  95.         END;
  96.  
  97.       { Stop driving, should coast to a stop. }
  98.       Drive(Heading, 0); {I.E., Stop}
  99.     END; {GoTo(X,Y)}
  100.  
  101.  
  102.     PROCEDURE Move;
  103.       { Move to a random spot on the playing field. }
  104.     VAR x, y       : Integer;
  105.     BEGIN
  106.       Sweep := 0; { Reset Sweep counter to zero. }
  107.       x := Random(900)+50;
  108.       y := Random(900)+50;
  109.       GOTO(x, y);
  110.     END; {Move}
  111.  
  112.  
  113. PROCEDURE End_Game;
  114.  
  115.   BEGIN {End_Game}
  116.     GoTo(0,0); {Lower Left Corner}
  117.     Angle := 10; {Sweep arc from 0 to 90 degrees only}
  118.     REPEAT
  119.       Delta := 10; { Start with widest scanning arc. }
  120.       Range := scan(Angle, Delta);
  121.       WHILE (Range > 40) AND (Range < 700) DO
  122.         { Must be far enough away to avoid self-damage. }
  123.         BEGIN
  124.           Aim(Angle, Delta); { Improve aim. }
  125.           cannon(Angle, Range); { Fire!! }
  126.           Range := scan(Angle, Delta); { Is foe still in sights? }
  127.         END;
  128.       Angle := Angle+20; { Look in adjacent target area. }
  129.       IF Angle > 90 THEN Angle := 10;
  130.     UNTIL Dead OR Winner;
  131.   END; {End_Game}
  132.  
  133.  
  134.   BEGIN {HotShot2 Main}
  135.     RaiseShield;
  136.     Angle := 0;
  137.     GoTo(500, 500); { Move to center of field. }
  138.     Sweep := 0; { Initialize Sweep counter to zero. }
  139.     REPEAT { Until Dead or Winner }
  140.       Delta := 10; { Start with widest scanning arc. }
  141.       Range := scan(Angle, Delta);
  142.       WHILE (Range > 40) AND (Range < 700) DO
  143.         { Must be far enough away to avoid self-damage. }
  144.         BEGIN
  145.           Sweep := 0; { Found foe, so reset Sweep to zero }
  146.           Aim(Angle, Delta); { Improve aim. }
  147.           cannon(Angle, Range); { Fire!! }
  148.           Range := scan(Angle, Delta); { Is foe still in sights? }
  149.         END;
  150.       Angle := Angle+20; { Look in adjacent target area. }
  151.       Sweep := Sweep+1;
  152.       IF Sweep >= 18 THEN
  153.         BEGIN { If robot has scanned a full circle, move elsewhere. }
  154.           LowerShield; {Don't need shield (as much) when moving}
  155.           Move;
  156.         END;
  157.  
  158.       RaiseShield; {Standing still so use shield}
  159.  
  160.       {"End" game strategy}
  161.       IF (Fuel < 200) OR (Damage > 70) THEN End_Game;
  162.  
  163.     UNTIL Dead OR Winner;
  164.  
  165.   END; {HotShot2 Main}
  166.  
  167.  
  168.  
  169.